<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "projectDB";
 
// 创建连接
$connect = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($connect->connect_error) {
    die("连接失败: " . $connect->connect_error);
} 
 
$connect->set_charset("utf8");

$sql = 'SELECT a.id, a.name, a.father_id, b.fathername FROM childrenclass a INNER JOIN fatherclass b ON a.father_id = b.id';
$result = $connect->query($sql);
 
if ($result->num_rows > 0) {
    // 输出数据
    var_dump($result);
    print_r($result->fetch_all(MYSQLI_ASSOC));
    // while($row = $result->fetch_assoc()) {
    //     echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br>";
    // }
} else {
    echo "0 结果";
}
// $conn->close();
?>